#ifndef MG_LCD_DRIVER_H
#define MG_LCD_DRIVER_H

#include "ite/itp.h" //for all ith driver (include GPIO) & MACRO
#include <sys/ioctl.h>
#include <unistd.h>

#define BackLight_PWM_Pin			CFG_GPIO_BACKLIGHT_PWM
#define BackLight_GPIO_MODE			CFG_GPIO_PWM_MODE
#define BackLight_PWM				(CFG_GPIO_PWM_NUMBER-1)
#define BackLight_PWM_Hz			1000UL	//PWM频率（Hz）
#define BackLight_PWM_DUTY			80UL	//占空比（%）

#define LCD_CS_GPIO		36
#define LCD_SDA_GPIO	31
#define LCD_SCL_GPIO	38
#define LCD_RST_GPIO	39

#define Set_LCD_SPI_SDA()	ithGpioSet(LCD_SDA_GPIO)
#define Clr_LCD_SPI_SDA()	ithGpioClear(LCD_SDA_GPIO)
#define Set_LCD_SPI_SCL()	ithGpioSet(LCD_SCL_GPIO)
#define Clr_LCD_SPI_SCL()	ithGpioClear(LCD_SCL_GPIO)
#define Set_LCD_SPI_CS()	ithGpioSet(LCD_CS_GPIO)
#define Clr_LCD_SPI_CS()	ithGpioClear(LCD_CS_GPIO)
#define Set_LCD_SPI_RES()	ithGpioSet(LCD_RST_GPIO)
#define Clr_LCD_SPI_RES()	ithGpioClear(LCD_RST_GPIO)

typedef enum
{
	Null_Action,				//无动作
	Left_Slide,					//左滑
	Right_Slide,				//右滑
	Up_Slide,					//上滑
	Down_Slide,					//下滑
	Forward,					//向前
	Backward,					//向后
	Clockwise_Rotation,			//顺时针转动
	Anticlockwise_Rotation,		//逆时针转动
	Wave,						//摇手
}CmdType;
typedef struct LCD_USER_ACTION_COMMAND
{
	CmdType User_Action;		//用户动作
	uint8_t Action_Times;		//动作次数
}Lcd_User_Action_Cmd;
extern Lcd_User_Action_Cmd Action_Cmd;


void BOARD_InitLcd(void);
static void _gpioPinInit(void);
void BOARD_InitLCD_SPI(void);
//LCD睡眠
void BOARD_LCD_Sleep(void);
void write_command(unsigned char y);
void write_data(unsigned char w);
//背光初始化
void BackLight_Init(void);
//设置背光PWM占空比(0-100)
void BackLight_Duty_Set(uint8_t DutyPercent);
//背光开
void BackLight_On(void);
//背光关
void BackLight_Off(void);
//LCD进入睡眠
void APP_Lcd_Sleep(void);
//LCD恢复
void APP_Lcd_Resume(void);
//清除用户操作事件
void Clear_User_Action(void);
#endif
